
package demo.issuetracker.controller;

import demo.issuetracker.model.CustomIdentity;
import demo.issuetracker.entity.User;
import demo.issuetracker.entity.Issue;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.In;


import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIData;
import javax.faces.event.ActionEvent;
import java.util.Map;
import java.util.List;

/**
 * Glue code to bind View Issues Service with the view framework (Seam). This class contains
 * a default implementation of the action methods. Please avoid reimplmenting the action methods in this class.
 * The purpose of this class is to declare properties which can be bound to the UI.
 * 
  * This page shows the user all of his team's issues.
  *
 * Automatically generated by clickframes
 * 
 * @author Vineet Manohar
 */
public abstract class GeneratedViewIssuesController extends Controller {
    @In("#{issueDao}") 
    protected demo.issuetracker.dao.IssueDao issueDao;

    @In("#{issueService}") 
    protected demo.issuetracker.entity.service.IssueService issueService;


    public User getLoggedInUser() {
        return identity.getUser();
    }

 
    /** the Issue row which on which the action was performed is stored on 
     * this field via the corresponding action listener if a user performs an action on the 
     * displayed Issue list 
     */


    /** $!Selected TeamIssues row */
    private Issue teamIssuesSelection;

    /** 
     * Get Selected TeamIssues
     *  
     * @return Selected TeamIssues
     */
    public Issue getTeamIssuesSelection() {
       return this.teamIssuesSelection;
    }

    /**
     * Set Selected TeamIssues
     *
     * @param teamIssuesSelection
     */
    public void setTeamIssuesSelection(Issue teamIssuesSelection) {
        this.teamIssuesSelection = teamIssuesSelection;
    }


    public void teamIssuesListener(ActionEvent actionEvent) {
        UIComponent tmpComponent = actionEvent.getComponent();

        while (null != tmpComponent && !(tmpComponent instanceof UIData)) {
            tmpComponent = tmpComponent.getParent();
        }

        UIData uiData = (UIData) tmpComponent;
        Object selectedRow = uiData.getRowData();
        if (selectedRow instanceof Issue) {
            this.teamIssuesSelection = (Issue) selectedRow;
        }
    }



    /** $!All issues belonging to user's team */
    private List<Issue> teamIssues;

    /** 
     * Get My Team's Issues
     *  
     * @return My Team's Issues
     */
    public List<Issue> getTeamIssues() {
       return this.teamIssues;
    }

    /**
     * Set My Team's Issues
     *
     * @param teamIssues
     */
    public void setTeamIssues(List<Issue> teamIssues) {
        this.teamIssues = teamIssues;
    }


    
	@SuppressWarnings("unused")
	private static final Log logger = LogFactory.getLog(GeneratedViewIssuesController.class);

	@In
	protected CustomIdentity identity;

    @Create
    public void init() {


        // initialize all file inputs
          // all inputs initialized here 
    }



    protected void initTeamIssues() {
        // if teamIssues has not been initialized, initialize it now
        if (getTeamIssues() == null) {
            setTeamIssues(loadTeamIssues());
        }
    }

    /**
     * clears the current value and loads the value again
     */
    protected void reloadTeamIssues() {
        clearTeamIssues();
        loadTeamIssues();
    }

    /**
     * clears the current value of My Team's Issues 
     */
    protected void clearTeamIssues() {
        setTeamIssues(null);
    }

    protected List<demo.issuetracker.entity.Issue> loadTeamIssues() {
        return issueDao.findTeamIssues(describe());
    }


	/**
	 * This method should be called before the page is loaded
	 * 
	 * All the page parameters should be consumed in this method
	 */    
    public String processPageParameters() {

        initTeamIssues();


          // if you need to add more code, override this method in the child class

        return null;
    }





 
 
 





    private static final long serialVersionUID = 1L;

  }// clickframes::version=2096856543::clickframes